package objects 
{
	import flash.geom.Point;
	import objects.Effect;
	import starling.core.Starling;
	import starling.display.MovieClip;
	import starling.display.Sprite;
	import starling.events.Event;
	/**
	 * ...
	 * @author Vượng
	 */
	public class Boom_Eff extends Effect
	{
		public function Boom_Eff(_sprite : Sprite, _pos : Point, _dame:Number, maxdamage : Number) 
		{
			super(_sprite,_pos);
			this.addEventListener(Event.ADDED_TO_STAGE, init);
			m_spriteMovie = new MovieClip(Assets.getSpriteSheet().getTextures("boomno_"), 4);
			m_spriteMovie.pivotX =  m_spriteMovie.width / 2;
			m_spriteMovie.pivotY =  m_spriteMovie.height / 2;	
			m_spriteMovie.x = m_pos.x;
			m_spriteMovie.y = m_pos.y;
			//Starling.juggler.add(m_spriteMovie);
			this.addChild(m_spriteMovie);
			this.m_coolDown = 20;
			m_minDamage = _dame;
			m_maxDamage = maxdamage;
			_sprite.addChild(this);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
		}

		override public function update(dt:Number):void
		{
			m_coolDown -= 1;
			if (m_spriteMovie.currentFrame < 3&&m_coolDown%5==0)
			{
				if (m_spriteMovie.currentFrame == 0)
				{
					if (database.instance.m_testPlaySound == true)
						database.instance.m_Sound.playSound("Sound_Canon");
				}
				m_spriteMovie.currentFrame += 1;
			}
		}
		public function CollisionWithArray ( _enemy : Array, dt : Number) :void
		{
			if ( _enemy != null)
			{
				for (var i:int = 0; i < _enemy.length; i++)
				{
				 	
				  if ( m_spriteMovie.getBounds(m_spriteMovie.parent).intersects( _enemy[i].getRect()) == true )
				  {				 
					  this.m_damage = randomRange (m_minDamage, m_maxDamage);
					  _enemy[i].m_hp = _enemy[i].m_hp - this.m_damage ;
					  
				  }
				}
				m_minDamage = 0;
				m_maxDamage = 0;
			  
			}
		}
		
	}

}